How to solve a problem with Array.sort Cannot assign to read only property '0' of object